package com.xieyong.leetcode;

import java.util.Arrays;

public class Leetcode2294 {
    public static void main(String[] args) {
        Leetcode2294 leetcode2294 = new Leetcode2294();
        int[] nums = {1,2,3,4,5,6,7,8,9};
        int k = 1;
        int i = leetcode2294.partitionArray(nums, k);
        System.out.println(i);
    }


    public int partitionArray(int[] nums, int k) {
        int len = nums.length;
        Arrays.sort(nums);
        int left = 0, right = 0,res = 1;
        while (right < len) {
            if (nums[right] - nums[left] > k) {
                left = right;
                res++;
            }
            right++;
        }
        return res;
    }
}
